package cn.new7as.cas5s.ui.apply;


import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.View;

import androidx.annotation.NonNull;

import com.hjq.http.EasyHttp;
import com.hjq.http.listener.OnHttpListener;

import cn.new7as.cas5s.tool.util.SharePreferenceUtils;
import cn.new7as.cas5s.ui.easy.netapi.ChangeBanknootpApi;
import cn.new7as.cas5s.ui.slideshow.BaseActivity;
import cn.new7as.cas5s.databinding.ActivityChangeforthBinding;
import cn.new7as.cas5s.tool.util.Utils;
import cn.new7as.cas5s.ui.easy.netapi.HttpData;
import cn.new7as.cas5s.ui.easy.netapi.GetBaseDataApi;
import cn.new7as.cas5s.ui.easy.netapi.SaveBaseDataApi;


public class ChangeForthActivity extends BaseActivity {


    private ActivityChangeforthBinding binding;

    @SuppressLint("MissingPermission")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActivityChangeforthBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        setop("Change Bank Card Details");
        show();
        getBase();
        initV();


    }

    @Override
    public void initV() {
        super.initV();

        setEtListener(binding.ifscBa, binding.accountnumberBa, binding.accountnumberconfirmationBa);

        binding.verifyme.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String ifscBa = binding.ifscBa.getText().toString();
                String accountnumberBa = binding.accountnumberBa.getText().toString();
                String accountnumberconfirmationBa = binding.accountnumberconfirmationBa.getText().toString();
                String upiBa = binding.upiBa.getText().toString();

                SaveBaseDataApi.Data data = new SaveBaseDataApi().new Data();
                data.type = 2;
                SaveBaseDataApi.Data4 data1 = new SaveBaseDataApi().new Data4();
                data1.code = ifscBa;
                data1.number = accountnumberBa;
                data1.confirmNumber = accountnumberconfirmationBa;
                data1.upi = upiBa;
                data.bankDetailInfo = data1;
                show();
                EasyHttp.post(ChangeForthActivity.this)
                        .api(new ChangeBanknootpApi(getunique(), ifscBa, new SharePreferenceUtils(ChangeForthActivity.this).getString("ucode",""), upiBa, accountnumberBa)).request(new OnHttpListener<HttpData<Object>>() {
                            @Override
                            public void onHttpSuccess(@NonNull HttpData<Object> result) {
                                hide();

                                finish();

                            }

                            @Override
                            public void onHttpFail(@NonNull Throwable throwable) {
                                deal(throwable);

                            }
                        });
            }


        });
    }

    void getBase() {
        EasyHttp.post(ChangeForthActivity.this)
                .api(new GetBaseDataApi(getunique(), 2)).request(new OnHttpListener<HttpData<GetBaseDataApi.Data>>() {


                    @Override
                    public void onHttpSuccess(@NonNull HttpData<GetBaseDataApi.Data> result) {
                        hide();
                        if (result.getResult() != null) {
                            binding.ifscBa.setText(result.getResult().code);
                            binding.accountnumberBa.setText(result.getResult().number);
                            binding.accountnumberconfirmationBa.setText(result.getResult().number);
                            binding.upiBa.setText(result.getResult().upi);

                            setTrue();
                        }
                    }

                    @Override
                    public void onHttpFail(@NonNull Throwable throwable) {
                        deal(throwable);

                    }
                });
    }

    @Override
    public void setFalse() {
        super.setFalse();
        binding.verifyme.setEnabled(false);
    }

    @Override
    public void setTrue() {
        super.setTrue();
        if (Utils.isStr(binding.ifscBa, binding.accountnumberBa, binding.accountnumberconfirmationBa))
            binding.verifyme.setEnabled(true);
    }


}